package com.ktjiaoyu.demo2;

/**
 * @ClassName : TextPaper
 * @Description :
 * @Author : Lzz
 * @Date: 2023/9/25 10:31:12
 */
public class TextPaper implements Paper{

    private int charPerLine = 16;
    private int linePerPage = 5;
    private String context = "";
    private int posX = 0;
    private int posY = 0;
    private int posP = 1;

    @Override
    public void putInChar(char c) {
        context += c;
        ++posX;
        if(posX == charPerLine){
            context += Paper.newLine;
            posX = 0;
            ++posY;
        }
        if(posY == linePerPage){
            context += "== 第"+posP+"页 ==";
            context += Paper.newLine+Paper.newLine;
            posY = 0;
            ++posP;
        }
    }

    @Override
    public String getContext() {
        String ret = this.context;
        if(!(posX == 0 && posY == 0)){
            int count = linePerPage - posY;
            for(int i = 0;i<count;i++){
                ret += Paper.newLine;
            }
            ret += "== 第"+posP+"页 ==";
        }
        return ret;
    }

    public void setCharPerLine(int charPerLine) {
        this.charPerLine = charPerLine;
    }

    public void setLinePerPage(int linePerPage) {
        this.linePerPage = linePerPage;
    }
}
